package com.liushuai.phoneguardian;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.liushuai.phoneguardian.db.dao.AddressDao;


public class AToolsActivity extends Activity implements OnClickListener {

	private SharedPreferences sp;
	private static final String TAG = "AToolsActivity";
	private Vibrator vbVibrator;
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_atools);
		vbVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

	}

	private AlertDialog alertDialog;
	private EditText et_dialog_num_addr_query;
	private TextView tv_dialog_num_addr;
	private Button bt_sure_dialog_num_addr_query;
	private Button bt_cancle_dialog_num_addr_query;

	public void atools_numberAddressQuery(View view) {
		Log.i(TAG, "点击了号码归属地查询按钮");
		showDialogNumberAddressQuery();
		
	}

	public void showDialogNumberAddressQuery() {
		AlertDialog.Builder builder = new Builder(this);
		View view = View.inflate(this, R.layout.dialog_number_address_query,
				null);
		et_dialog_num_addr_query = (EditText) view
				.findViewById(R.id.et_dialog_num_addr_query);
		tv_dialog_num_addr = (TextView) view
				.findViewById(R.id.tv_dialog_num_addr);
		bt_sure_dialog_num_addr_query = (Button) view
				.findViewById(R.id.bt_sure_dialog_num_addr_query);
		bt_cancle_dialog_num_addr_query = (Button) view
				.findViewById(R.id.bt_cancle_dialog_num_addr_query);
		bt_sure_dialog_num_addr_query.setOnClickListener(this);
		bt_cancle_dialog_num_addr_query.setOnClickListener(this);
		alertDialog = builder.create();
		alertDialog.setView(view, 0, 0, 0, 0);
		alertDialog.show();

	}

	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub

		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu_lost_activity, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_sure_dialog_num_addr_query:
			
			Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
			et_dialog_num_addr_query.setAnimation(shake);
			vbVibrator.vibrate(200);
			String addr = AddressDao.getAddress(et_dialog_num_addr_query
					.getText().toString());
			tv_dialog_num_addr.setText(addr);
			break;
		case R.id.bt_cancle_dialog_num_addr_query:
			alertDialog.dismiss();
			break;

		}

		
		
	}

}
